package ui 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import model.Model;
	import utils.SpriteUtil;
	import utils.TextFieldUtil;
	
	/**
	 * ...
	 * @author usual
	 */
	public class Explanation extends MovieClip 
	{
		private var _container:MovieClip;
		private var _leftText:MovieClip;
		private var _rightText:MovieClip;
		private var _littleTitle:LittleTitle;
		private var _scrollLeft:Scroller;
		private var _scrollRight:Scroller;
		private var _bg:Sprite;
		private var _closeBtn:CloseBtn;
		
		public function Explanation() 
		{
			addEventListener(Event.ADDED_TO_STAGE, _build);
		}
		
		private function _build(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, _build);
			stage.addEventListener(Event.RESIZE, stageResize);
			addBg();
			_container = new MovieClip();
			addChild(_container);
			addTitle();
			addLeftCol();
			addRightCol();
			addCloseBtn();
			resize();
			stageResize();
		}
		
		private function addCloseBtn():void 
		{
			_closeBtn = new CloseBtn();
			_container.addChild(_closeBtn);
			_closeBtn.buttonMode = true;
			_closeBtn.addEventListener(MouseEvent.CLICK, _closeThis);
		}
		
		private function _closeThis(e:MouseEvent=null):void 
		{
			this.visible = false;
			//stage.removeEventListener(Event.RESIZE, stageResize);
			//this.parent.removeChild(this);
		}
		
		private function addBg():void 
		{
			_bg = SpriteUtil.drawRectSprite(100, 100,0x221f1f);
			addChild(_bg);
		}
		
		private function stageResize(e:Event=null):void 
		{
			if (_bg)
			{
				_bg.width = stage.stageWidth;
				_bg.height = stage.stageHeight;
			}
			if (_container)
			{
				_container.x = int((stage.stageWidth / 2) - (_container.width / 2));
				_container.y = 150;
			}
			
		}
		
		private function resize():void 
		{
			_scrollLeft.y = _littleTitle.y + _littleTitle.height + 34;
			_scrollRight.x = _leftText.x + _leftText.width + 50;
			if (_closeBtn)
			{
				_closeBtn.x = _scrollRight.x + _scrollRight.width + 22;
			}
		}
		
		private function addRightCol():void 
		{
			_rightText = new MovieClip();
			var txt:TextField = new TextField();
			txt.autoSize =  TextFieldAutoSize.LEFT;
			txt.selectable = false;
			txt.width = 265;
			txt.multiline = txt.wordWrap = true;
			//txt.htmlText = String(Model.instance.getUiLabel('explanationRight'));
			TextFieldUtil.setText(txt, String(Model.instance.getUiLabel('explanationRight')));
			_rightText.addChild(txt);
			
			var _scrollMc:ScrollerMc = new ScrollerMc();
			_scrollRight = new Scroller(_scrollMc);
			_container.addChild(_scrollRight);
			_scrollRight.setupDO(_rightText, 265, 487, "on", "on");
		}
		
		private function addLeftCol():void 
		{
			_leftText = new MovieClip()
			var txt:TextField = new TextField();
			txt.autoSize =  TextFieldAutoSize.LEFT;
			txt.selectable = false;
			txt.width = 348;
			txt.multiline = txt.wordWrap = true;
			//txt.htmlText = String(Model.instance.getUiLabel('explanationLeft'));
			TextFieldUtil.setText(txt, String(Model.instance.getUiLabel('explanationLeft')));
			_leftText.addChild(txt);
			
			var _scrollMc:ScrollerMc = new ScrollerMc();
			_scrollLeft = new Scroller(_scrollMc);
			_container.addChild(_scrollLeft);
			_scrollLeft.setupDO(_leftText, 348, 340, "on", "on");
			
		}
		
		private function addTitle():void 
		{
			_littleTitle = new LittleTitle();
			_container.addChild(_littleTitle);
		}
		
		
	}

}